<?php
class PNTambonArray extends PNObjectExArray {
  function PNTambonArray($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'votedata_tambon';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';
    $this->_objJoin[]     = array ( 'join_table'  =>  'votedata_province',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('pro_name'),
                            'compare_field_table' =>  'pro_id',
                            'compare_field_join'  =>  'id');

    $this->_objJoin[]     = array ( 'join_table'  =>  'votedata_district',
                            'join_field'          =>  array('name'),
                            'object_field_name'   =>  array('dis_name'),
                            'compare_field_table' =>  'dis_id',
                            'compare_field_join'  =>  'id');

    $this->_init($init, $where);
  }

  function genSort(){
    return " ORDER BY pro_name, dis_name, tam_name ASC";
  }

  function genFilter(){
    $form  = FormUtil::getPassedValue ('form', false);
    $wheres = array();
    if ($form['pro_id'] && intval($form['pro_id'])) $wheres[] = " tam_pro_id = ".$form['pro_id'];
    if ($form['dis_id'] && intval($form['dis_id'])) $wheres[] = " tam_dis_id = ".$form['dis_id'];

    return implode(' AND ', $wheres) ;
  }
}
